package com.mz.mattress.client.config;

import com.mz.mattress.client.config.demo.Dog;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * https://mp.weixin.qq.com/s/EzKhb__2kgORbHNQ3RdSOw
 */
@Configuration
@Import({Dog.class, AnimalImportSelector.class, AnimalImportBeanDefinitionRegistrar.class})
public class ExecutorManager {

    @Bean("executor1")
    public Executor importTaskExecutor1() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setBeanName("executor1");
        return executor;
    }

    // 动态创建bean
    @Bean("executor2")
    @Conditional(ExecutorCondition.class)
    public Executor importTaskExecutor2() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setBeanName("executor2");
        return executor;
    }

}
